#!/usr/bin/env python
# -*- coding: utf-8 -*-
###########################################################################
#   Copyright (C) 2008 by Serj Poltavsky                                  #
#   serge.uliss at gmail.com                                              #
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 3 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
#   This program is distributed in the hope that it will be useful,       #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#   GNU General Public License for more details.                          #
#                                                                         #
#   You should have received a copy of the GNU General Public License     #
#   along with this program. If not, see <http://www.gnu.org/licenses/>   #
###########################################################################

import unittest
from tools.videoencode import VideoEncode

class TestVideoConvert(unittest.TestCase):
    def setUp(self):
        self.f = VideoEncode('in', 'out', 'pal', (4, 3))

    def test_init(self):
        self.assertEqual(self.f.src, 'in')
        self.assertEqual(self.f.dest, 'out')
        self.assertEqual(self.f.format, 'pal')
        self.assertEqual(self.f.aspect, (4,3))

    def test_format(self):
        self.assertEqual(self.f.format, 'pal')
        self.assertEqual(self.f._VideoEncode__options['-ofps'], 25)
        self.f.format = 'ntsc'
        self.assertEqual(self.f.format, 'ntsc')
        self.assertRaises(RuntimeError, self.f.set_format, 'foo')
        self.assertEqual(self.f._VideoEncode__options['-ofps'], '30000/1001')
        self.f.format = 'pal'
        self.assertEqual(self.f._VideoEncode__options['-ofps'], 25)

    def test_aspect(self):
        self.assertEqual(self.f.aspect, (4,3))
        self.assertEqual(self.f._VideoEncode__codec_options['aspect'], '4/3')
        self.f.aspect = (16,9)
        self.assertEqual(self.f._VideoEncode__codec_options['aspect'], '16/9')
        self.assertEqual(self.f.aspect, (16,9))
        self.assertRaises(RuntimeError, self.f.set_aspect, (7,6))

    def test_cmd(self):
        self.assert_(len(self.f.make_cmd()) > 0)

    def test_hq(self):
        self.assertEqual(self.f._VideoEncode__codec_options.get('dc'), None)
        self.assertEqual(self.f._VideoEncode__codec_options['vbitrate'], 5000)
        self.f.set_codec_options_hq()
        self.assertEqual(self.f._VideoEncode__codec_options['vbitrate'], 8000)
        self.assertEqual(self.f._VideoEncode__codec_options.get('dc'), 10)
        self.f.set_codec_options_lq()
        self.assertEqual(self.f._VideoEncode__codec_options.get('dc'), None)
        self.assertEqual(self.f._VideoEncode__codec_options['vbitrate'], 5000)